import 'dart:ui';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:sui_shou_pai/news/bottom_tool_bar.dart';

import '../comment/announcement_comment_list.dart';
import '../data/announcement_list_item_data.dart';

class AnnouncementDetail extends StatefulWidget {
  final AnnouncementListItemData item;

  AnnouncementDetail({Key key, this.item}) : super(key: key);

  @override
  AnnouncementDetailState createState() => AnnouncementDetailState();
}

class AnnouncementDetailState extends State<AnnouncementDetail> {
  Function callback;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    announcementList = AnnouncementCommentList(announcementId: widget.item.id);
    callback = (var isRefresh) {
      if (isRefresh) {
        announcementList.refreshComment.call(true);
      }
    };
  }

  AnnouncementCommentList announcementList;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.white,
        appBar: AppBar(
          centerTitle: true,
          title: Text('公告详情'),
          elevation: 0,
          actions: [
            IconButton(
              icon: Icon(Icons.more_horiz),
              onPressed: () {},
            ),
          ],
        ),
        body: Column(
          children: <Widget>[
            Expanded(
                child: ListView(
              padding: EdgeInsets.all(16),
              children: <Widget>[
                initAnnouncementTitle(),
                initAnnouncementTimePublisher(),
                initAnnouncementContent(),
                announcementList
              ],
            )),
            BottomToolBar(
              currentContentType: "announcement",
              currentContentId: widget.item.id,
              callback: callback,
            )
          ],
        ));
  }

  Widget initAnnouncementTitle() {
    return Container(
      child: Text(
        widget.item.title,
        style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold),
      ),
    );
  }

  Widget initAnnouncementTimePublisher() {
    return Container(
      alignment: Alignment.centerRight,
      margin: EdgeInsets.only(top: 12, bottom: 12),
      child: Text(
        '${widget.item.time}  ${widget.item.publisher}',
        style: TextStyle(fontSize: 14, color: Colors.grey),
      ),
    );
  }

  Widget initAnnouncementContent() {
    return Container(
      child: Text(
        widget.item.content,
        textAlign: TextAlign.left,
        style: TextStyle(fontSize: 18, height: 1.5),
      ),
    );
  }
}
